namespace NC.Infrastructure.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Init : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.ApiRecords",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Url = c.String(),
                        AccessToken = c.String(),
                        QueryData = c.String(),
                        FormData = c.String(),
                        CreateAt = c.DateTime(nullable: false),
                        Person_Id = c.Int(),
                        Target_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.People", t => t.Person_Id)
                .ForeignKey("dbo.Targets", t => t.Target_Id)
                .Index(t => t.Person_Id)
                .Index(t => t.Target_Id);
            
            CreateTable(
                "dbo.People",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Role = c.Int(nullable: false),
                        Name = c.String(),
                        SchoolNumber = c.String(),
                        Image = c.String(),
                        InSchoolTime = c.Int(nullable: false),
                        Description = c.String(),
                        TickName = c.String(),
                        Password = c.String(),
                        Audit = c.Boolean(nullable: false),
                        CreateAt = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.TargetPersons",
                c => new
                    {
                        Id = c.Int(nullable: false),
                        CreateAt = c.DateTime(nullable: false),
                        Target_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Targets", t => t.Target_Id)
                .ForeignKey("dbo.People", t => t.Id)
                .Index(t => t.Id)
                .Index(t => t.Target_Id);
            
            CreateTable(
                "dbo.Targets",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Url = c.String(nullable: false),
                        Name = c.String(nullable: false),
                        FavirateIco = c.String(),
                        Description = c.String(),
                        AppId = c.String(),
                        Status = c.Int(nullable: false),
                        CreatedAt = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ContentExtendParams",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Key = c.String(),
                        Name = c.String(),
                        Selector = c.String(),
                        InfoType = c.Int(nullable: false),
                        Target_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Targets", t => t.Target_Id)
                .Index(t => t.Target_Id);
            
            CreateTable(
                "dbo.ContentParams",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ContainerSelector = c.String(),
                        TitleSelector = c.String(),
                        AuthorSelector = c.String(),
                        ComeUpTimeSelector = c.String(),
                        ContentSelector = c.String(),
                        TypeSelector = c.String(),
                        CreatedAt = c.DateTime(nullable: false),
                        Target_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Targets", t => t.Target_Id)
                .Index(t => t.Target_Id);
            
            CreateTable(
                "dbo.UrlLists",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Url = c.String(),
                        Name = c.String(),
                        ContentSelector = c.String(),
                        ASelector = c.String(),
                        EnablePager = c.Boolean(nullable: false),
                        PagerSelector = c.String(),
                        PostBodyParams = c.String(),
                        QueryStringParams = c.String(),
                        Method = c.String(),
                        PerRequestPagerNum = c.String(),
                        Target_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Targets", t => t.Target_Id)
                .Index(t => t.Target_Id);
            
            CreateTable(
                "dbo.Applies",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Description = c.String(),
                        BackUpDescription = c.String(),
                        Audit = c.Int(nullable: false),
                        CreateAt = c.DateTime(nullable: false),
                        Person_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.People", t => t.Person_Id)
                .Index(t => t.Person_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Applies", "Person_Id", "dbo.People");
            DropForeignKey("dbo.ApiRecords", "Target_Id", "dbo.Targets");
            DropForeignKey("dbo.ApiRecords", "Person_Id", "dbo.People");
            DropForeignKey("dbo.TargetPersons", "Id", "dbo.People");
            DropForeignKey("dbo.TargetPersons", "Target_Id", "dbo.Targets");
            DropForeignKey("dbo.UrlLists", "Target_Id", "dbo.Targets");
            DropForeignKey("dbo.ContentParams", "Target_Id", "dbo.Targets");
            DropForeignKey("dbo.ContentExtendParams", "Target_Id", "dbo.Targets");
            DropIndex("dbo.Applies", new[] { "Person_Id" });
            DropIndex("dbo.UrlLists", new[] { "Target_Id" });
            DropIndex("dbo.ContentParams", new[] { "Target_Id" });
            DropIndex("dbo.ContentExtendParams", new[] { "Target_Id" });
            DropIndex("dbo.TargetPersons", new[] { "Target_Id" });
            DropIndex("dbo.TargetPersons", new[] { "Id" });
            DropIndex("dbo.ApiRecords", new[] { "Target_Id" });
            DropIndex("dbo.ApiRecords", new[] { "Person_Id" });
            DropTable("dbo.Applies");
            DropTable("dbo.UrlLists");
            DropTable("dbo.ContentParams");
            DropTable("dbo.ContentExtendParams");
            DropTable("dbo.Targets");
            DropTable("dbo.TargetPersons");
            DropTable("dbo.People");
            DropTable("dbo.ApiRecords");
        }
    }
}
